package com.settlement.system.common.enums;

import com.settlement.system.common.util.common.FasUtil;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 收退款-渠道 枚举类
 * @author user
 */
public enum FollowUpResponsibilityEnum {
    /**
     * O2O客服
     */
    O2O_CUSTOMER_SERVICE("O2O客服","O2O_CUSTOMER_SERVICE"),
    /**
     * 物流部
     */
    LOGISTICS_DEPT("物流部","LOGISTICS_DEPT"),
    /**
     * 电商客服
     */
    E_COMMERCE_CUSTOMER_SERVICE("电商客服","E_COMMERCE_CUSTOMER_SERVICE"),
    /**
     * 品牌客服
     */
    BRAND_CUSTOMER_SERVICE("品牌客服","BRAND_CUSTOMER_SERVICE"),
    /**
     * 售后
     */
    AFTER_SALE("售后","1"),
    /**
     * 物流
     */
    LOGISTICS("物流","2"),
    /**
     * 商家
     */
    MERCHANT("商家","3"),
    /**
     * 地区
     */
    AREA("地区","4"),
    /**
     * 集团物流
     */
    JT_LOGISTICS("集团物流","5"),
    /**
     * 电商客服
     */
    DS_CUSTOMER_SERVICE("电商客服","6"),
    /**
     * 集团客服
     */
    JT_CUSTOMER_SERVICE("集团客服","7");



    private String name;

    private String no;

    FollowUpResponsibilityEnum(String name, String no) {
        this.name = name;
        this.no = no;
    }

    public String getName() {
        return name;
    }

    public String getNo() {
        return no;
    }


    /**
     * 根据名称获取编码
     * @param no
     * @return
     */
    public static String getNameByNo(String no) {
        FollowUpResponsibilityEnum[] enums = FollowUpResponsibilityEnum.values();
        for (int index = 0; index < enums.length; index++) {
            if(enums[index].getNo().equals(no)){
                return enums[index].getName();
            }
        }
        return null;
    }

    public static String getNoStringByName(String filterStr){
        if(StringUtils.isBlank(filterStr)){
            return null;
        }
        FollowUpResponsibilityEnum[] values = FollowUpResponsibilityEnum.values();
        List<FollowUpResponsibilityEnum> list = new ArrayList<FollowUpResponsibilityEnum>();
        for (int index = 0; index < values.length; index++) {
            FollowUpResponsibilityEnum value = values[index];
            list.add(value);
        }
        list = list.stream()
                .filter(f->f.getName().contains(filterStr.trim()))
                .collect(Collectors.toList());
        List<String> noList = new ArrayList<String>();
        list.forEach(f->{noList.add(f.getNo());});
        String noString = String.join(",", noList);
        noString = FasUtil.formatInQueryCondition(noString);
        return noString;
    }

    public static void main(String[] args) {
        System.out.println(getNoStringByName(""));
    }
}
